package logic

import (
	"cart/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelAllLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartDelAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelAllLogic {
	return &CartDelAllLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartDelAllLogic) CartDelAll(req *types.CartDelAllRequest) (resp *types.Response, err error) {
	// todo:清空购物车
	all, err := l.svcCtx.CartRpc.CartDelAll(l.ctx, &cart.CartDelAllRequest{UserId: req.UserId})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "清空成功",
		Data: all,
	}, nil
}
